# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
# This source file is part of the Cangjie project, licensed under Apache-2.0
# with Runtime Library Exception.
#
# See https://cangjie-lang.cn/pages/LICENSE for license information.

import os

def default_value(ty : str) -> str:
  if 'Int' in ty: return '1'
  if 'Float' in ty: return '1.0'
  if ty is 'Rune': return '\'1\''
  if ty is 'String': return '"1"'
  raise

dir = os.path.dirname(os.path.realpath(__file__))
path = dir + '/test_' + os.path.basename(dir) + '_{}.cj'
template = '''
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 * This source file is part of the Cangjie project, licensed under Apache-2.0
 * with Runtime Library Exception.
 *
 * See https://cangjie-lang.cn/pages/LICENSE for license information.
 */

/*
  @Assertion:   4.16(6) Note that the relational operators are non-associative, i.e., an expression like a < b < c is
                invalid
                main(): Int64 {{
                    3 < 4 < 5 // error: `<` is non-associative
                    3 == 3 != 4 // error: `==` and `!=` are non-associative
                    return 0
                }}
  @Description: Checks that expression a {op} b {op} c is invalid.
  @Mode: compileonly
  @Negative: yes
  @Structure: single
  @CompileWarning: no
  @Comment: Auto-generated by gen.py
*/

main() {{
    var a : {ty} = {val}
    var b : {ty} = {val}
    var c : {ty} = {val}
    a {op} b {op} c
    0
}}
'''

counter = 2

for ty in ['Int8', 'Int16', 'Int32', 'Int64', 'UInt8', 'UInt16', 'UInt32', 'UInt64', 'Float16', 'Float32', 'Float64', 'String', 'Rune']:
  for op in ['==', '!=', '>', '<', '>=', '<=']:
    counter += 1
    contents = template.format(ty=ty, val=default_value(ty), op=op)
    with open(path.format(str(counter).zfill(2)), 'w') as file:
      file.write(contents)
